package com.yusong.algorithm.array;

import java.util.Arrays;

public class RemoveDuplicates80 {


    public static void main(String[] args) {
        int[] grid = {0, 0, 1, 1, 1, 1, 2, 3, 3};

        RemoveDuplicates80 main = new RemoveDuplicates80();

        main.removeDuplicates(grid);

        System.out.println(Arrays.toString(grid));
    }


    public int removeDuplicates(int[] nums) {
        int length = nums.length;
        if (length <= 2) {
            return length;
        }
        int slowIndex = 0;
        //子序列中出现次数
        int count = 1;
        for (int i = 1; i < length; i++) {
            int currentValue = nums[i];
            System.out.println("A "+i+ " | "+ slowIndex+" | " + currentValue +" | " + nums[slowIndex]);
            int lastValue = nums[slowIndex];
            if(currentValue == lastValue){
                count++;
            }else {
                count = 1;
            }
            if(count <= 2){
                slowIndex++;
                if(slowIndex != i){
                    nums[slowIndex] = currentValue;
                }
            }
            System.out.println("B "+i+ " | "+ slowIndex+" | " + currentValue +" | " + nums[slowIndex] +" |" +count);
        }
        return slowIndex + 1;
    }
}
